package com.kaka.bluetoothble.base;
/*
    ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ 
       Author   :  lixiaodaoaaa
       Date     :  2018/6/21
       Time     :  11:21
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
 */

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import java.lang.ref.WeakReference;

public class BaseActivity extends AppCompatActivity{
    
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
    }
    
    private Handler mHandler;
    
    public Handler getHandler(){
        if (null == mHandler) {
            mHandler=new BaseHandler(this);
        }
        return mHandler;
    }
    
    protected void handleMessage(Message msg){
    
    }
    
    
    private static class BaseHandler extends Handler{
        private WeakReference<BaseActivity> weakRefrenceActivity=null;
        
        public BaseHandler(BaseActivity activity){
            weakRefrenceActivity=new WeakReference<>(activity);
        }
        
        @Override
        public void handleMessage(Message msg){
            BaseActivity currentActiviy=weakRefrenceActivity.get();
            if (currentActiviy == null) {
                super.handleMessage(msg);
                return;
            }
            currentActiviy.handleMessage(msg);
        }
    }
 
}
